home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraphix / cpiehist.c < prev    next >
Text File  |  1986-05-28  |  2KB  |  107 lines

  1. /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
  2. #include    <stdio.h>
  3. #define    EXTERN    extern
  4. #include    <typedef.h>
  5.  
  6.  
  7. void PieHistoDem()
  8. {
  9.     extern char    *strcpy();
  10.  
  11.     double    sum,x1,y1,x2,y2,InRadius,OutRadius;
  12.     int        i,n;
  13.     PieArray    a;
  14.     PlotArray    b;
  15.     int        ch;
  16.     WrkString    NumText;
  17.     char    string[80];
  18.  
  19.     n = 5;
  20.     a[0].area = 25;
  21.     a[1].area = 17.5;
  22.     a[2].area = 9.6;
  23.     a[3].area = 21;
  24.     a[4].area = 35;
  25.     strcpy(a[0].text, "JAN. ");
  26.     strcpy(a[1].text, "FEB. ");
  27.     strcpy(a[2].text, "MAR. ");
  28.     strcpy(a[3].text, "APR. ");
  29.     strcpy(a[4].text, "MAY  ");
  30.  
  31.     for (i = 0; i < n; i++)
  32.         b[1 + 2 * i] = a[i].area;
  33.  
  34.     ClearScreen();
  35.     SetColorWhite();
  36.  
  37.     DefineWindow(1,0,0,XMaxGlb,YMaxGlb);
  38.     DefineHeader(1,"BOTH A PIE AND A BAR CHART");
  39.     SelectWindow(1);
  40.     SetHeaderOn();
  41.     SetBackground(0);
  42.     DrawBorder();
  43.  
  44.     for (i = 0; i < n; i++) {
  45.         GotoXY(60, 3+i);
  46.         sprintf(string, "%s=%6.2lf", a[i].text, a[i].area);
  47.         DisplayString(string);
  48.     }
  49.  
  50.     DefineWindow(2,(int)(XMaxGlb/10),(int)(YMaxGlb/10),
  51.         (int)(XMaxGlb*6/10),(int)(YMaxGlb*7/10));
  52.     DefineHeader(2,"A PIE CHART");
  53.     DefineWorld(2, 0., 0., 1000., 1000.);
  54.     SelectWorld(2);
  55.     SelectWindow(2);
  56.     SetHeaderOn();
  57.     SetBackground(0);
  58.     DrawBorder();
  59.  
  60.  
  61.     a[0].area = -a[0].area;
  62.     SetAspect(1.0);
  63.  
  64.     x1 = 500.;
  65.     y1 = 500.;
  66.  
  67.     x2 = 600.;
  68.     y2 = 350.;
  69.  
  70.     InRadius = 0.7;
  71.     OutRadius = 1.25;
  72.  
  73.     DrawCartPie(x1,y1,x2,y2,InRadius,OutRadius,a,n,2,1);
  74.  
  75.     a[0].area = -a[0].area;
  76.  
  77.     DefineWindow(3,(int)(XMaxGlb/2),(int)(YMaxGlb/2),
  78.         (int)(XMaxGlb*9/10),(int)(YMaxGlb*9/10));
  79.     DefineHeader(3,"A BAR CHART");
  80.     DefineWorld(3, 0., 0., 10., 60.);
  81.     SelectWorld(3);
  82.     SelectWindow(3);
  83.     SetHeaderOn();
  84.     SetBackground(0);
  85.     DrawBorder();
  86.  
  87.     DrawHistogram(b,n,TRUE,5);
  88.  
  89.     for (i = 0; i < n; i++) {
  90.         sprintf(string, "   %s", a[i].text);
  91.         DrawTextW((double)(10/n)*i,(double)10,1,string);
  92.         sprintf(string, "%6.2lf", a[i].area);
  93.         DrawTextW((double)(10/n)*i,(double)16,1,string);
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. main()
  100. {
  101.     InitGraphic();
  102.     PieHistoDem();
  103.     inkey();
  104.     LeaveGraphic();
  105. }
  106.  
  107.